package com.qyhl.webtv.module_circle.circle.userlist;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.android.material.tabs.TabLayout;
import com.gyf.immersionbar.ImmersionBar;
import com.qyhl.webtv.basiclib.base.BaseActivity;
import com.qyhl.webtv.basiclib.base.BaseIViewPresenter;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.utils.action.ActionConstant;
import com.qyhl.webtv.commonlib.utils.action.ActionLogUtils;
import com.qyhl.webtv.module_circle.R;
import com.qyhl.webtv.module_circle.R2;
import com.qyhl.webtv.module_circle.circle.userlist.fragment.UserListFragment;
import com.umeng.analytics.MobclickAgent;
import com.weavey.loading.lib.LoadingLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by qyhl on 2018/2/8.
 * @author qyhl
 */

@Route(path = ARouterPathConstant.USER_LIST)
public class UserListActivity extends BaseActivity {
    @BindView(R2.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;
    @BindView(R2.id.load_mask)
    LoadingLayout loadMask;

    //PageAdapter
    private UserListPageAdapter mViewPageAdapter;
    // Frgaments
    private List<Fragment> mFragmentList;

    private List<String> mList;

    @Autowired(name = "type")
    int type =0;//0 关注  1 粉丝


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected int getContentView() {
        return R.layout.circle_activity_user_list;
    }

    @Override
    protected void setImmersionBar(ImmersionBar mImmersionBar) {
        setDefaultImmerBar();
    }

    @Override
    protected BaseIViewPresenter initBaseIViewPresenter() {
        return null;
    }

    @Override
    protected void init() {
        initView();
    }

    @Override
    protected void setListener() {

    }

    /**
     * 初始化
     */
    private void initView() {
        loadMask.setStatus(LoadingLayout.Success);
        mFragmentList = new ArrayList<>();
        mList = new ArrayList<>();

        mList.add("关注");
        mList.add("粉丝");
        mFragmentList.add(UserListFragment.newInstance(1));
        mFragmentList.add(UserListFragment.newInstance(2));

        mViewPageAdapter = new UserListPageAdapter(getSupportFragmentManager(), mFragmentList);
        mViewPageAdapter.setData(mList);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);

        viewPager.setAdapter(mViewPageAdapter);
        viewPager.setOffscreenPageLimit(2);

        tabLayout.setupWithViewPager(viewPager);

        mViewPageAdapter.notifyDataSetChanged();
        if(type == 0){
            viewPager.setCurrentItem(0);
        }else{
            viewPager.setCurrentItem(1);
        }
        ActionLogUtils.getInstance().onPause(this, ActionConstant.FRIENDFANS);
    }

    @Override
    public void onResume() {
        super.onResume();
        //baidu
        //umeng
        MobclickAgent.onPageStart("圈子用户列表");
        MobclickAgent.onResume(this);

        ActionLogUtils.getInstance().onResume(this, ActionConstant.FRIENDFANS);
    }

    @Override
    public void onPause() {
        super.onPause();
        //baidu
        //umeng
        MobclickAgent.onPageEnd("圈子用户列表");
        MobclickAgent.onPause(this);
    }
}
